-
-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
!!! FEATURE: References on creation and Copy #5148
Conversation
Do not merge yet, probably want to refactor some of the code in the DTOs. I think we should make the "collection of references for one reference property" an explicit DTO, as the code like this feels a bit too messy for my taste... |
On the upside the somewhat weird and unfinished reference snapshots can be removed with this. |
And forgot to adapt legacy migration tests (which rely on specific event payloads, see below, before I adjust those we should decide which way to go with b/c)... |
oh and I should mention that at the moment this is not forgiving to the existing events. We could do this in the respective fromArray constructors of the DTOs and just "upcast" from the old structure on the fly without much problem, or add a migration for the events. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this, some early thoughts before ill play with this ;)
Neos.ContentRepository.Core/Classes/Feature/Common/NodeReferencingInternals.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferenceNameToEmpty.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferenceToWrite.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesToWrite.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferenceToWrite.php
Show resolved
Hide resolved
This reworks references so that multiple reference properties can be set via a single command and also references can be attached to `CreateNodeAggregateWithNode` which is also used for copying nodes.
1ee4c27
to
1612659
Compare
# Conflicts: # Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php
I remember we discussed this some time ago so i was wondering where it goes from now? I think we discussed for an alternative way than to use a "hacky" NodeReferenceNameToEmpty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ill re review later:)
Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php
Outdated
Show resolved
Hide resolved
...Tests/Tests/Behavior/Features/05-NodeReferencing/04-SetNodeReferences_PropertyScopes.feature
Show resolved
Hide resolved
...Tests/Tests/Behavior/Features/05-NodeReferencing/04-SetNodeReferences_PropertyScopes.feature
Outdated
Show resolved
Hide resolved
...Repository.BehavioralTests/Tests/Behavior/Features/NodeCopying/CopyNode_NoDimensions.feature
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/Common/NodeReferencingInternals.php
Outdated
Show resolved
Hide resolved
....ContentRepository.Core/Classes/Feature/NodeCreation/Command/CreateNodeAggregateWithNode.php
Outdated
Show resolved
Hide resolved
....ContentRepository.Core/Classes/Feature/NodeCreation/Command/CreateNodeAggregateWithNode.php
Outdated
Show resolved
Hide resolved
.../Classes/Feature/NodeCreation/Command/CreateNodeAggregateWithNodeAndSerializedProperties.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/NodeDuplication/Dto/NodeReferenceSnapshot.php
Outdated
Show resolved
Hide resolved
...ntentRepository.Core/Classes/Feature/NodeReferencing/Dto/SerializedNodeReferencesForName.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/SerializedNodeReference.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php
Show resolved
Hide resolved
Neos.ContentRepository.LegacyNodeMigration/Classes/NodeDataToEventsProcessor.php
Show resolved
Hide resolved
Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php
Show resolved
Hide resolved
Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php
Show resolved
Hide resolved
…`fromReferences`
… override previous values
…aggregate ids to write for ONE reference name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work.. and a lot of it, yikes.
Some rather minor issues
Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php
Outdated
Show resolved
Hide resolved
$this->getDatabaseConnection()->delete($this->tableNamePrefix . '_referencerelation', [ | ||
'sourcenodeanchor' => $anchorPoint->value, | ||
'name' => $referencesForProperty->referenceName->value | ||
]); | ||
|
||
foreach ($referencesForProperty->references as $reference) { | ||
// set new | ||
$referenceRecord = new ReferenceRelationRecord( | ||
$anchorPoint, | ||
$referencesForProperty->referenceName, | ||
$position, | ||
$reference->properties, | ||
$reference->targetNodeAggregateId | ||
); | ||
$referenceRecord->addToDatabase($this->getDatabaseConnection(), $this->tableNamePrefix); | ||
$position++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, can't we turn this into two atomic queries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me the pg adapter is out of scope and there are no tests ... but i fixed it for doctrine
Neos.ContentRepository.Core/Classes/Feature/NodeDuplication/Dto/NodeSubtreeSnapshot.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesForName.php
Show resolved
Hide resolved
$this->requireNodeTypeToDeclareReference($sourceNodeAggregate->nodeTypeName, $referenceName); | ||
$scopeDeclaration = $sourceNodeType->getReferences()[$referenceName->value]['scope'] ?? ''; | ||
$scope = PropertyScope::tryFrom($scopeDeclaration) ?: PropertyScope::SCOPE_NODE; | ||
// TODO: Optimize affected sets into one event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason why we don't?
The current state would be like publishing multiple NodePropertiesWereSet
events for each property.
Couldn't we just build up the $referencesByName
array and then build the event outside of the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted:)
Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php
Show resolved
Hide resolved
and the test has to be adjusted as it fails now earlier:
|
and remove duplicated `fromReferences` naming in chain, now its `create` for root level
Okay i fixed the tests again and added some documentation ... i also got rid of the duplicate SetNodeReferences::create(
$node->workspaceName,
$node->aggregateId,
$node->originDimensionSpacePoint,
NodeReferencesToWrite::create(
// sets the 3 nodes as references
NodeReferencesForName::fromTargets(
ReferenceName::fromString('first-reference'),
NodeAggregateIds::fromArray(['node-aggregate-id-1', 'node-aggregate-id-2', 'node-aggregate-id-3'])
),
// unset previously set references (as we do NOT merge the values)
NodeReferencesForName::createEmpty(
ReferenceName::fromString('second-reference')
),
// create a simple node reference and additionally a reference with an additional property
NodeReferencesForName::fromReferences(
ReferenceName::fromString('third-reference'),
[
NodeReferenceToWrite::fromTarget(NodeAggregateId::fromString('node-aggregate-id-6')),
NodeReferenceToWrite::fromTargetAndProperties(NodeAggregateId::fromString('node-aggregate-id-5'), PropertyValuesToWrite::fromArray([
'propertyOnReference' => 'Hi im living on the edge ;)'
])),
])
)
) |
... like in set serialized properties. That way fewer `NodeReferencesWereSet` are emitted. At most only one per scope of `PropertyScope` Also the `PropertyScope` enum was marked internal as its not exposed in apis and no use for the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay i further made the optimisations basti suggested. Now its truly finished id say <3
Thank you so much for your effort!
This reworks references so that multiple reference properties can be set via a single command and also references can be attached to
CreateNodeAggregateWithNode
which is also used for copying nodes.The serialization format is adapted to allow multiple reference properties, which also affects all behat tests with references.
To migrate existing events run:
./flow migrateevents:migratesetreferencestomultinameformat
Marked breaking as it requires an event migration.
This requires neos/neos-ui#3844 for the UI
A behat test to show reference copies work was added.
Upgrade Instructions
The API to set references changed a little, please adjust accordingly.
This is a simple example which covers all cases: